<?php
/**
 * Created by PhpStorm.
 * User: Jerry
 * Date: 2017/3/15
 * Time: 13:51
 */

namespace SDXApi\Adapters;


/**
 * Class AlbumAdapter
 * @package SDXApi\Service
 */
class AlbumAdapter
{
	/**
	 * @var array
	 */
	protected $instance = array(
		1	=>	'SDXApi\Service\AlbumTemplateTextService',
		2	=>	'SDXApi\Service\AlbumTemplateGoodsService',
		3	=>	'SDXApi\Service\AlbumTemplateAlbumsService',
        4   =>  'SDXApi\Service\AlbumTemplateCategoryService',
	);

	/**
	 * @var
	 */
	protected $app;

	/**
	 * AlbumAdapter constructor.
	 * @param $type
	 */
	public function __construct($type)
	{
		$instanceName = $this->instance[$type];

		if (class_exists($instanceName)) {
			$this->app = new $instanceName();
		}
		else{
			E('获取数据失败', 5001);
		}

		return $this;
	}

	/**
	 * Created by Jerry
	 * @param array $album
	 * @param int $userId
	 * @param int $wid
	 * @return bool
	 */
	public function handle($album = array(), $userId = 0, $wid = 8)
	{
		if (get_class($this->app)) {
			return $this->app->handle($album, $userId, $wid);
		}

		return false;
	}

}